package com.bqy.myokgo;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.apkfuns.logutils.LogUtils;
import com.bqy.myokgo.base.MyBaseActivity;
import com.bqy.myokgo.utils.NoDoubleClickListener;

import java.util.ArrayList;
import java.util.List;

import static br.com.zbra.androidlinq.Linq.stream;

public class LinqActivity extends MyBaseActivity {

    Button button1;
    Button button2;
    TextView tv1;
    List<String> ss = new ArrayList<>();
    List<Integer> ii = new ArrayList<>();
    boolean sss;
    boolean iii;

    @Override
    public View setContentView() {
        return View.inflate(this, R.layout.activity_linq, null);
    }

    @Override
    public void iniGreate(Bundle savedInstanceState) {
        super.iniGreate(savedInstanceState);
        ss.add("bcb");
        ss.add("ccc");
        ss.add("aca");
        ss.add("sss");
        ss.add("ccc");
        ss.add("ccc");
        ss.add("scs");
        ss.add("sss");

        ii.add(1);
        ii.add(645);
        ii.add(3);
        ii.add(8);
        ii.add(45);
        ii.add(98);
        ii.add(98879);
        ii.add(54);
    }

    @Override
    public void iniView() {
        button1 = findViewById(R.id.bu1);
        button2 = findViewById(R.id.bu2);
        tv1 = findViewById(R.id.tv1);
    }

    @Override
    public void iniClick() {
        button1.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                LogUtils.e(ii);
                LogUtils.e(ss);
                if (sss) {
                    List<String> contactNames =
                            stream(ss)
                                    //筛选
                                    .where(c -> c.contains("c"))
                                    .toList();
                    LogUtils.e(contactNames);
                    String a = "";
                    for (int i = 0; i < contactNames.size(); i++) {
                        a += contactNames.get(i).toString() + "\n";
                    }
                    tv1.setText(a);
                    sss = false;
                } else {
                    LogUtils.e(ss);
                    String a = "";
                    for (int i = 0; i < ss.size(); i++) {
                        a += ss.get(i).toString() + "\n";
                    }
                    tv1.setText(a);
                    sss = true;
                }
            }
        });
        button2.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                LogUtils.e(ii);
                LogUtils.e(ss);
                if (iii) {
                    List<Integer> integerList =
                            stream(ii)
                                    //大到小排序
                                    .orderByDescending(c -> c)
                                    .toList();
                    LogUtils.e(integerList);
                    String a = "";
                    for (int i = 0; i < integerList.size(); i++) {
                        a += integerList.get(i).toString() + "\n";
                    }
                    tv1.setText(a);
                    iii = false;
                } else {
                    List<Integer> integerList =
                            stream(ii)
                                    //小到大排序
                                    .orderBy(c -> c)
                                    .toList();
                    LogUtils.e(integerList);
                    String a = "";
                    for (int i = 0; i < integerList.size(); i++) {
                        a += integerList.get(i).toString() + "\n";
                    }
                    tv1.setText(a);
                    iii = true;
                }
            }
        });
    }
}
